import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {HousesService} from '../../providers/houses.service';
import { Storage } from '@ionic/storage';

/**
 * Generated class for the EvaluationPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-evaluation',
  templateUrl: 'evaluation.html',
  providers:[HousesService]

})
export class EvaluationPage {
  users:any;
  house:any;
  comment;
  userInfo;
  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    private hoSer:HousesService,
    private storage:Storage,

  ) {
  }

  ionViewDidLoad() {
    let that = this;
    that.users=this.navParams.get('users');
    that.house=this.navParams.get('house');
  }




  agree(arrangeId){
    let that = this;
    // console.log("Sdsds");
    // that.userName = that.storage.get('userName');
    that.storage.ready().then(() =>{
      that.storage.get('user').then((user) =>{
        that.userInfo = user;

        that.hoSer.agree({"arrangeId":arrangeId,"houseId":that.house.houseId,"userId":that.userInfo.userId},function (result) {
          console.log(result.stateCode);
          if(result.stateCode == 17){
            console.log("点赞成功");
            that.hoSer.getArrInfo({"houseId":that.house.houseId},function (result) {

              console.log(result);
              that.users=result;
            })
          }else{
            console.log("点赞失败");
          }
        });

      });

    })



    // $(".user_comment").children('.fa-thumbs-o-up').eq(index).attr("class", "fa fa-thumbs-up");
  }


  addArr(comment){
// alert(comment);
    let that = this;
    that.comment = comment.value;

    // that.userName = that.storage.get('userName');
    that.storage.ready().then(() =>{
      that.storage.get('user').then((user) =>{
          that.userInfo = user;
        that.hoSer.addArrInfo({"comment":that.comment,"userId":that.userInfo.userId,"houseId":that.house.houseId},function (result) {
          if(result.stateCode == 15){
            console.log("评论成功");
            that.hoSer.getArrInfo({"houseId":that.house.houseId},function (result) {

              console.log(result);
              that.users=result;
            })
          }else{
            console.log("评论失败");
          }
        });
      });

    })

  }
}
